package com.bawei.park2211a.login

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil

import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bawei.base.bean.LoginEntity
import com.bawei.park2211a.R
import com.bawei.park2211a.databinding.ItemNoticeBinding
import com.chad.library.adapter.base.listener.OnItemClickListener

class LoginAdapter : PagingDataAdapter<LoginEntity, LoginAdapter.LoginViewHolder>(diff) {
    private var mOnItemClickListener: OnItemClickListener? = null
    companion object {
        var diff = object : ItemCallback<LoginEntity>() {
            override fun areItemsTheSame(oldItem: LoginEntity, newItem: LoginEntity): Boolean {
                return oldItem.id == newItem.id
            }

            override fun areContentsTheSame(oldItem: LoginEntity, newItem: LoginEntity): Boolean {
                return oldItem == newItem
            }

        }
    }
    fun setOnItemClickListener(listener: OnItemClickListener?) {
        this.mOnItemClickListener = listener
    }
    class LoginViewHolder(itemView: View) : ViewHolder(itemView) {
        var binding: ItemNoticeBinding? = DataBindingUtil.bind(itemView)
    }

    override fun onBindViewHolder(holder: LoginViewHolder, position: Int) {
        val item = getItem(position)!!
        holder.itemView.setOnClickListener {
            mOnItemClickListener?.OnClickListener(position)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LoginViewHolder {
        return LoginViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_notice, parent, false)
        )
    }
    interface OnItemClickListener{
        fun OnClickListener(position: Int)
    }
}